home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / dev / Oberon4Amiga / Dialogs / DialogButtons.Mod (.txt) < prev    next >
Oberon Text  |  1994-11-28  |  8KB  |  190 lines

  1. Syntax10.Scn.Fnt
  2. Syntax10i.Scn.Fnt
  3. StampElems
  4. Alloc
  5. 27 Oct 94
  6. Syntax10b.Scn.Fnt
  7. Chicago10.Scn.Fnt
  8. MODULE DialogButtons; (* ww  *)
  9.     (** extended version Markus Knasm
  10. ller 25.May.94 -   
  11.     IMPORT DialogFrames, Dialogs, DialogStaticTexts, DialogTexts, Display, Files, Fonts, GraphicUtils, In, Input, 
  12.         Oberon, TextFrames, Texts, Viewers;
  13.     CONST ML = 0; MM = 1; MR = 2;  W* = 30; H* = 20; grey1 = 12; grey2 = 13; grey3 = 14; black = 15; white = 0;
  14.     TYPE
  15.         Item* = POINTER TO ItemDesc;
  16.         ItemDesc* = RECORD(Dialogs.ObjectDesc)
  17.             fnt-: Fonts.Font;  (** font that is used to display the name of the button *)
  18.         END;
  19.     VAR w0: Texts.Writer;
  20.     PROCEDURE (b: Item) Copy* (VAR dup: Dialogs.Object);
  21.     (** allocates dup and makes a deep copy of o. Before calling this methode dup should be equal NIL *)
  22.         VAR x: Item;
  23.     BEGIN
  24.         IF dup = NIL THEN NEW (x); dup := x ELSE x := dup(Item) END; 
  25.         b.Copy^ (dup); x.fnt := b.fnt; 
  26.     END Copy;
  27.     PROCEDURE (b: Item) Draw1 (x, y: INTEGER; pressed: BOOLEAN; f: Display.Frame);
  28.         VAR mode, w, h, yh, ox, oy, cx: INTEGER; 
  29.     BEGIN
  30.         b.GetDim (ox, oy, w, h); 
  31.         IF b.selected THEN mode := Display.invert ELSE mode := Display.paint END;
  32.         GraphicUtils.DrawBox (f, pressed, x, y, w, h, mode);
  33.         yh := y + (h DIV 2) - ((b.fnt.minY + b.fnt.maxY) DIV 2);
  34.         IF h - (yh - y)  > b.fnt.maxY THEN 
  35.             GraphicUtils.DrawString (f, b.name, x + 3, yh, w - 4, b.fnt, mode, cx) 
  36.         END
  37.     END Draw1;
  38.     PROCEDURE (b: Item) Draw* (x, y: INTEGER; f: Display.Frame);
  39.     (** displays the object at (x, y) in frame f *)
  40.     BEGIN b.Draw1 (x, y, FALSE, f)    
  41.     END Draw;
  42.     PROCEDURE (b: Item) Print* (x, y: INTEGER);
  43.     (** prints the object at printer coordinates (x, y) *)
  44.         VAR w, h, ox, oy, yh, cx: INTEGER; fnth: LONGINT;
  45.     BEGIN
  46.         b.GetPDim (ox, oy, w, h); GraphicUtils.PrintBox (x, y, w, h);  
  47.         fnth := ((b.fnt.maxY - b.fnt.minY) * Dialogs.dUnit) DIV Dialogs.pUnit DIV 2;
  48.         yh := y + (h DIV 2) - SHORT (fnth); 
  49.         IF h - (yh - y) > ((b.fnt.maxY * SHORT (Dialogs.dUnit)) DIV Dialogs.pUnit) THEN 
  50.             GraphicUtils.PrintString (b.name, x + 3, yh, w - 4, b.fnt, cx) 
  51.         END
  52.     END Print;
  53.     PROCEDURE (b: Item) Track (x, y: INTEGER; keys: SET; f: Display.Frame; p: Dialogs.Panel; x0, y0: INTEGER);
  54.         VAR bx, by, bw, bh: INTEGER; keysum: SET; t: Texts.Text;
  55.     BEGIN
  56.         b.GetDim (bx, by, bw, bh);
  57.         IF (keys = {ML}) OR (keys = {MM}) OR (keys = {MR}) THEN 
  58.             Oberon.RemoveMarks(x0 + bx, y0 + by, bw, bh);
  59.             b.Draw1 (x0 + bx, y0 + by, TRUE, f);
  60.             keysum := keys;
  61.             REPEAT Input.Mouse(keys, x, y); keysum := keysum + keys;
  62.                 Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  63.             UNTIL keys = {};
  64.             Oberon.RemoveMarks(x0 + bx, y0 + by, bw, bh);
  65.             b.Draw1 (x0 + bx, y0 + by, FALSE, f);
  66.             IF (keysum = {ML}) OR (keysum = {MM}) OR (keysum = {MR}) THEN
  67.                 IF b.cmd[0] # 0X THEN
  68.                     DialogTexts.GetParText (b.par, p, t);
  69.                     b.CallCmd (f, Viewers.This (x, y), t)
  70.                 END
  71.             END
  72.         ELSE Oberon.DrawCursor(Oberon.Mouse, Oberon.Arrow, x, y)
  73.         END
  74.     END Track;
  75.     PROCEDURE (b: Item) Handle* (f: Display.Frame; VAR m: Display.FrameMsg);
  76.     (** handles messages which were sent to frame f *)
  77.     BEGIN
  78.         b.Handle^ (f, m);
  79.         WITH f: DialogFrames.Frame DO 
  80.             WITH m: Oberon.InputMsg DO
  81.                 IF m.id = Oberon.track THEN b.Track (m.X, m.Y, m.keys, f, f.panel, f.X, f.Y + f.H) END
  82.             ELSE
  83.             END
  84.         ELSE
  85.         END
  86.     END Handle;
  87.     PROCEDURE (b: Item) Load* (VAR r: Files.Rider);
  88.     (** reads the object from rider r *)
  89.         VAR fntname: ARRAY 32 OF CHAR;
  90.     BEGIN b.Load^( r); Files.ReadString (r, fntname); b.fnt := Fonts.This (fntname);  
  91.     END Load;
  92.     PROCEDURE (b: Item) Store* (VAR r: Files.Rider);
  93.     (** writes the object to rider r *)
  94.     BEGIN b.Store^ (r); Files.WriteString (r, b.fnt.name)
  95.     END Store;
  96.     PROCEDURE (b: Item) SetFont* (fnt: Fonts.Font);
  97.     (** sets the font with which the text is shown *)
  98.     BEGIN b.fnt := fnt; b.Restore (); IF b.panel # NIL THEN b.panel.MarkMenu END
  99.     END SetFont;
  100.     PROCEDURE WriteToObjectStr (o: DialogTexts.Item; VAR p: Dialogs.Panel; n: ARRAY OF CHAR);
  101.         VAR t: Texts.Text; 
  102.     BEGIN
  103.         t := o.GetText (); Texts.WriteString (w0, n); Texts.Append (t, w0.buf);
  104.     END WriteToObjectStr;
  105.     PROCEDURE (b: Item) Edit* ();
  106.     (** opens a dialog for editing the properties of the object *)
  107.         VAR on: Dialogs.Object; t: Texts.Text; fnt: Fonts.Font; 
  108.     BEGIN
  109.         b.Edit^ (); 
  110.         on := Dialogs.editPanel.NamedObject ("name"); t := on(DialogTexts.Item).GetText ();
  111.         Texts.ChangeLooks (t, 0, t.len, {0}, b.fnt, 0, 0);
  112.     END Edit;
  113.     PROCEDURE (b: Item) Update* (p: Dialogs.Panel);
  114.     (** sets the properties of the object to the values defined in the dialog p opened with Edit *)
  115.         VAR o: Dialogs.Object; t: Texts.Text; r: Texts.Reader; ch: CHAR; 
  116.     BEGIN
  117.         o := p.NamedObject ("name"); t := o(DialogTexts.Item).GetText ();
  118.         Texts.OpenReader (r, t, 0); Texts.Read (r, ch); 
  119.         IF (r.fnt # NIL) & (r.fnt # b.fnt) THEN b.SetFont (r.fnt) END;
  120.         b.Update^ (p); 
  121.     END Update;
  122.     PROCEDURE Insert*;
  123.     (** Insert ([name] [x y w h] | ^ ) inserts a button - item in the panel containing the caret position *)
  124.         VAR x, y, x1, y1, w, h: INTEGER; b: Item; p: Dialogs.Panel; name: ARRAY 64 OF CHAR;
  125.     BEGIN 
  126.         NEW (b); 
  127.         DialogFrames.GetCaretPosition(p, x, y);
  128.         IF (p # NIL) THEN 
  129.             b.Init; b.fnt := Fonts.This ("Syntax10b.Scn.Fnt"); 
  130.             In.Open; In.Name (name);
  131.             IF ~In.Done THEN COPY ("", name); In.Open END;
  132.             b.SetName (name); 
  133.             In.Int (x1); In.Int (y1); In.Int (w); In.Int (h);
  134.             IF ~In.Done THEN x1 := x; y1 := y; w := W; h := H 
  135.             ELSE
  136.                 IF w < 0 THEN w := W END;
  137.                 IF h < 0 THEN h := H END
  138.             END;
  139.             b.SetDim (x1, y1, w, h, FALSE); p.Insert (b, FALSE)
  140.         ELSE
  141.             Dialogs.res := Dialogs.noPanelSelected 
  142.         END;
  143.         IF Dialogs.res # 0 THEN Dialogs.Error ("DialogButtons") END;
  144.     END Insert;
  145.     PROCEDURE DeInit;
  146.         VAR s: DialogStaticTexts.Item; b: Item; t: DialogTexts.Item;
  147.     BEGIN
  148.         NEW (Dialogs.deInit);
  149.         NEW (s); s.Init; s.SetDim (6, -36, 45, 20, FALSE); 
  150.         s.SetString ("Name"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt")); 
  151.         Dialogs.deInit.Insert (s, FALSE);
  152.         NEW (s); s.Init; s.SetDim (13, -79, 40, 20, FALSE); 
  153.         s.SetString ("X"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt")); 
  154.         Dialogs.deInit.Insert (s, FALSE);
  155.         NEW (s); s.Init; s.SetDim (13, -117, 40, 20, FALSE); 
  156.         s.SetString ("Y"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt")); 
  157.         Dialogs.deInit.Insert (s, FALSE);
  158.         NEW (s); s.Init; s.SetDim (8, -155, 40, 20, FALSE); 
  159.         s.SetString ("Cmd"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt")); 
  160.         Dialogs.deInit.Insert (s, FALSE);
  161.         NEW (s); s.Init; s.SetDim (155, -79, 19, 18, FALSE); 
  162.         s.SetString ("W"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt")); 
  163.         Dialogs.deInit.Insert (s, FALSE);
  164.         NEW (s); s.Init; s.SetDim (153, -116, 19, 18, FALSE); 
  165.         s.SetString ("H"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt")); 
  166.         Dialogs.deInit.Insert (s, FALSE);
  167.         NEW (s); s.Init; s.SetDim (8, -193, 40, 20, FALSE);
  168.         s.SetString ("Par"); s.SetFont (Fonts.This ("Syntax12b.Scn.Fnt")); 
  169.         Dialogs.deInit.Insert (s, FALSE);
  170.         NEW (b); b.Init; b.SetDim (288, -107, 80, 35, FALSE); b.SetName ("Do");
  171.         b.SetFont (Fonts.This ("Syntax12b.Scn.Fnt")); b.SetCmd ("Dialog.Do");
  172.         Dialogs.deInit.Insert (b, FALSE);
  173.         NEW (t); t.Init; t.SetDim (52, -40, 140, 25, FALSE); t.SetName ("name");
  174.         Dialogs.deInit.Insert (t, FALSE);
  175.         NEW (t); t.Init; t.SetDim (54, -79, 70, 22, FALSE); t.SetName ("x");
  176.         Dialogs.deInit.Insert (t, FALSE);
  177.         NEW (t); t.Init; t.SetDim (54, -116, 70, 22, FALSE); t.SetName ("y");
  178.         Dialogs.deInit.Insert (t, FALSE);
  179.         NEW (t); t.Init; t.SetDim (54, -155, 195, 22, FALSE); t.SetName ("cmd");
  180.         Dialogs.deInit.Insert (t, FALSE);
  181.         NEW (t); t.Init; t.SetDim (177, -79, 70, 22, FALSE); t.SetName ("w");
  182.         Dialogs.deInit.Insert (t, FALSE);
  183.         NEW (t); t.Init; t.SetDim (177, -117, 70, 22, FALSE); t.SetName ("h");
  184.         Dialogs.deInit.Insert (t, FALSE);
  185.         NEW (t); t.Init; t.SetDim (54, - 193, 195, 22, FALSE); t.SetName ("par");
  186.         Dialogs.deInit.Insert (t, FALSE)
  187.     END DeInit;
  188. BEGIN Texts.OpenWriter (w0); DeInit;
  189. END DialogButtons.
  190.